package susebs.pb.travel_server.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import susebs.pb.travel_server.domain.PageDto;
import susebs.pb.travel_server.domain.Result;
import susebs.pb.travel_server.service.HotelPackageService;
import susebs.pb.travel_server.service.LandmarkPackageService;
import susebs.pb.travel_server.service.NavigationsService;
import susebs.pb.travel_server.service.PackagesService;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 *套餐控制层
 */
@RestController
@RequestMapping("/packages")
@CrossOrigin
public class PackagesController {
    @Resource
    private PackagesService packagesService;
    @Resource
    private NavigationsService navigationsService;
    @Resource
    private LandmarkPackageService landmarkPackageService;
    @Resource
    private HotelPackageService hotelPackageService;

    @PostMapping("/queryByPage")
    public Result queryByPage(@RequestBody PageDto pageDto){
        PageInfo list = packagesService.queryAllPksByPage(pageDto);
        if(list.getList().isEmpty())return Result.buildFail("未查到相关信息！");
        ArrayList res = navigationsService.getListsAndPics(list.getList());
        return Result.buildSuccess(res);
    }

    /**
     * 获取套餐内关联的景点结果集（列表+图片）
     * @param pkId
     * @return
     */
    @GetMapping("/queryLmPackages")
    public Result queryLmPackages(Long pkId){
        //套餐关联的景区id
        ArrayList ids = landmarkPackageService.queryAll(pkId);
        if(ids.isEmpty())return Result.buildFail("改套餐无关联景区！");
        //景区id查得列表
        ArrayList list = landmarkPackageService.queryByIds(ids);
        //结果集
        ArrayList res = navigationsService.getListsAndPics(list);

        return Result.buildSuccess(res);

    }

    /**
     * 获取套餐内关联的酒店结果集（列表+图片）
     * @param pkId
     * @return
     */
    @GetMapping("/queryHotelPackages")
    public Result queryHotelPackages(Long pkId){
        //套餐关联的酒店id
        ArrayList ids = hotelPackageService.queryAll(pkId);
        if(ids.isEmpty())return Result.buildFail("改套餐无关联酒店！");
        //酒店id查得列表
        ArrayList list = hotelPackageService.queryByIds(ids);
        //结果集
        ArrayList res = navigationsService.getListsAndPics(list);

        return Result.buildSuccess(res);
    }



}
